package com.example.leetdemo.finash;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Solution2399 {

    public boolean checkDistances(String s, int[] distance) {
        Map<String, Integer> map = new HashMap<>();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            String c = s.substring(i, i + 1);
            set.add(c);
            if (map.containsKey(c)) {
                Integer value = i - map.get(c) - 1;
                Character d = c.charAt(0);
                distance[(int) (d - 'a')] -= value;
            } else {
                map.put(c, i);
            }
        }
        for (int i = 0; i < distance.length; i++) {
            Character character = (char) (i + 'a');
            if (distance[i] != 0 && set.contains(character + "")) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution2399 solution2399 = new Solution2399();
        System.err.println(solution2399.checkDistances(
                "abaccb", new int[] {1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
                )
        );
    }
}
